<?php

// 获取连珠数据
// GET pk10.renju
// http://sg.io/api?pk10.renju&vx=v1

namespace app\api\resource\pk10;
use app\api\lib\Page;

class Renju
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取连珠数据';
    // 参数
    public $_param  = [
        'page' => '请求页,默认1',
        'show' => '请求记录数量,默认10',
        'vx'   => '位',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1);
        $show  = $request->get('show/d',10);
        $vx    = $request->param('vx/s','','trim');

        if ( empty($vx) ) return [422,'位必须'];

        if ( !in_array($vx,['v1','v2','v3','v4','v5']) ) return [422,'位无效'];

        $table = 'pk10';
        $where = '';
        $order = 'no DESC';
        $pagelist = Page::run($table,$where,$order,$page,$show);
        // p($pagelist);die;

        if ( !empty($pagelist['list']) ) {
            $item = [];
            foreach ($pagelist['list'] as $key => $val) {
                // $item[ 'No.' . substr($val['no'],3) ] = intval($val[$vx]);
                $item[ '#' . $val['no'] ] = intval($val[$vx]);
            }
            // p($item);die;
            $pagelist['list'] = $item;
        }

        // p($pagelist);die;

        return [200,$pagelist];
    }
}
